"""
Language configuration for PDF Splitter.
"""

from typing import Dict, List, Tuple
from PyQt6.QtCore import QLocale

# Supported languages
SUPPORTED_LANGUAGES: Dict[str, Tuple[str, str]] = {
    "en_US": ("English", "English"),
    "zh_CN": ("中文", "Chinese (Simplified)"),
}

# Default language
DEFAULT_LANGUAGE = "en_US"

def get_language_name(language_code: str) -> str:
    """Get language display name."""
    return SUPPORTED_LANGUAGES.get(language_code, ("Unknown", "Unknown"))[0]

def get_language_native_name(language_code: str) -> str:
    """Get language native name."""
    return SUPPORTED_LANGUAGES.get(language_code, ("Unknown", "Unknown"))[1]

def get_supported_languages() -> List[str]:
    """Get list of supported language codes."""
    return list(SUPPORTED_LANGUAGES.keys())

def detect_system_language() -> str:
    """Detect system language."""
    system_locale = QLocale.system()
    system_lang = system_locale.name()

    # Check exact match
    if system_lang in SUPPORTED_LANGUAGES:
        return system_lang

    # Check language-only match (e.g., 'zh' matches 'zh_CN')
    lang_only = system_lang.split('_')[0]
    for code in SUPPORTED_LANGUAGES:
        if code.split('_')[0] == lang_only:
            return code

    return DEFAULT_LANGUAGE